package com.api.gbhg.zengping.web;

import com.alibaba.fastjson.JSON;
import com.api.gbhg.zengping.dao.PropertyManagementCostDao;
import com.api.gbhg.zengping.dao.TotalBudgetDao;
import weaver.conn.RecordSet;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.util.HashMap;
import java.util.Map;

/**
 * @program: gbhg-oa
 * @description: 预算总额报表
 * @author: Mr.zeng
 * @create: 2021-03-03 11:34
 **/
public class TotalBudgetAction {
    // 操作sql类
    private final PropertyManagementCostDao rmcd=new PropertyManagementCostDao();

    /**
     * 预算总额列表
     * @param map
     * @return
     */
    @POST
    @Path("/totalBudgetList")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    public String totalBudgetList(Map map){
        Map<String,Object> mapMap=new HashMap<>();
        RecordSet rs = TotalBudgetDao.selectByList(map);
        Map<String,Object>[] list=new HashMap[rs.getArray().size()];
        int count=0;
        //预算总额合计   审批中费用合计 可用额度合计 实际发生数合计 执行率合计
        Double zeSum=0.0;
        Double djSum=0.0;
        Double kySum=0.0;
        Double yySum=0.0;
        Double zxlSum=0.0;
        while (rs.next()){
            list[count]=new HashMap<>();
            //年度
            list[count].put("nd",rs.getString("nd"));
            //申报单位
            RecordSet sbdw = rmcd.getSBDWById(rs.getInt("sbdw"));
            sbdw.next();
            list[count].put("sbdw",sbdw.getString("SUBCOMPANYNAME"));
            //申报科室
            RecordSet sbks = rmcd.getSBKSById(TotalBudgetDao.getSBKS(rs.getString("lcjlid")));
            sbks.next();
            list[count].put("sbks",sbks.getString("departmentmark"));

            //总额
            Double ze = rs.getDouble("ze");
            list[count].put("ze",ze);
            //冻结金额
            double dj = rs.getDouble("dj");
            list[count].put("dj",dj);
            Double syed = rs.getDouble("syed");
            //剩余额度
            list[count].put("syed",syed);
            //报销数
            Double yy=ze-dj-syed;
            list[count].put("bxs",yy);
            //执行率
            String percent2 = LeadingPortalsAction.getPercent2(Math.abs(syed - ze), ze);
            Double zxl=Double.valueOf(percent2.substring(0,percent2.indexOf("%")));
            list[count].put("zxl",percent2);
            zeSum+=ze;
            djSum+=dj;
            kySum+=syed;
            yySum+=yy;
            zxlSum+=zxl;
            count++;
        }
        mapMap.put("list",list);
        map.put("total",TotalBudgetDao.selectByListCount(map));
        mapMap.put("zeSum",zeSum);
        mapMap.put("djSum",djSum);
        mapMap.put("kySum",kySum);
        mapMap.put("yySum",yySum);
        mapMap.put("zxlSum",zxlSum+"%");
        return JSON.toJSONString(mapMap);
    }

    public static void main(String[] args) {
        System.out.println("0%".substring(0,"0%".indexOf("%")));
    }
}
